package app.itgungnir.compose.wan.business.message

import android.content.res.Configuration
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import app.itgungnir.compose.wan.theme.WanComposePreviewTheme
import app.itgungnir.compose.wan.widgets.*

@Composable
fun MessageItem(item: Message?) {
    item ?: return
    WanCardColumn {
        Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
            if (item.isRead == 0) {
                WanDot(modifier = Modifier.padding(end = 5.dp))
            }
            WanInfo(content = "来自 ${item.fromUser} 的 ${item.tag}")
        }
        Spacer(modifier = Modifier.height(5.dp))
        WanTitle(content = item.title)
        Spacer(modifier = Modifier.height(5.dp))
        WanDescription(content = item.message, maxLines = Int.MAX_VALUE)
        Spacer(modifier = Modifier.height(5.dp))
        WanInfo(modifier = Modifier.align(Alignment.End), content = item.niceDate)
    }
}

@Preview(name = "MessageItem light mode", showBackground = false)
@Preview(name = "MessageItem dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = false)
@Composable
private fun MessageItemPreview() {
    WanComposePreviewTheme {
        val message = Message(
            title = "字节跳动-懂车帝-大力招 Android 研发，站长所在团队哈，一起并肩作战。",
            message = "字节跳动-懂车帝-大力招 Android 研发~  站长所在团队哈，一起并肩作战，点击查看详情，果断投简历哈。",
            fromUser = "鸿洋",
            isRead = 0,
            tag = "系统消息",
            niceDate = "2020-11-12 22:53"
        )
        MessageItem(item = message)
    }
}
